package com.umakr.demo.controller;

import com.umakr.demo.model.Teacher;
import com.umakr.demo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.swing.event.ListDataEvent;
import java.util.List;

/**
 * Created by yangliu on 2017/8/18.
 */
@Controller
@RequestMapping("/TeacherController")
public class TeacherController {
    @Autowired
    TeacherService teacherService;

//    显示教师管理的页面
    @RequestMapping("/showTeacher")
    public String showTeacher(){
        return "StudentManage/teacher";
    }

//    返回教师的数据
    @RequestMapping("/teacherData")
    @ResponseBody
    public List teacherData(){
        List<Teacher> list = teacherService.showAll();
        return list;
    }

//    保存数据
    @RequestMapping("/saveTeacher")
    @ResponseBody
    public List saveTeacher(Long tid,String tname,String tsex){
        Teacher teacher = new Teacher(tid,tname,tsex);
        teacherService.saveTeacher(teacher);
        List<Teacher> list = teacherService.showAll();
        return list;
    }

//    删除数据
    @RequestMapping("/deleteTeacher")
    @ResponseBody
    public List deleteTeacher(Long tid,String tname,String tsex){
        Teacher teacher = new Teacher(tid,tname,tsex);
        teacherService.deleteTeacher(teacher);
        List<Teacher> list = teacherService.showAll();
        return list;
    }

//    修改教师数据
    @RequestMapping("/updataTeacher")
    @ResponseBody
    public List updataTeacher(Long tid,String tname,String tsex){
        Teacher teacher = new Teacher(tid,tname,tsex);
        teacherService.updataTeacher(teacher);
        List<Teacher> list = teacherService.showAll();
        return list;
    }
}
